package com.dehui.traders.ui.market.rank;

import android.content.Context;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.adapter.RankListAdapter;
import com.dehui.traders.bean.BaseListResponse;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.bean.RankBean;
import com.dehui.traders.service.NetImpl;
import com.dehui.traders.utils.SimulatedDataManager;
import com.dehui.traders.widgets.BaseViewHolder;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.functions.Action0;

/**
 * Created by hqq on 18.4.2.
 */

public class RankMarketViewModel extends BaseViewModel{

    private final RankMarketFragment fragment;

    public RankMarketViewModel(Context context, RankMarketFragment fragment) {
        super(context);
        this.fragment = fragment;
    }

    public void tradeupdownList(String code, int pageNum) {
        Call<BaseListResponse<PlateListBean>> call = NetImpl.updownlist(code, pageNum);
        call.enqueue(new Callback<BaseListResponse<PlateListBean>>() {
            @Override
            public void onResponse(Call<BaseListResponse<PlateListBean>> call, Response<BaseListResponse<PlateListBean>> response) {
                BaseListResponse<PlateListBean> response1 = response.body();
                if (response1 == null || response1.result ==null)
                    return;
                List<PlateListBean> list = response1.result;
                ArrayList<PlateListBean> rankList = new ArrayList<>();
                for (PlateListBean bean : list){
                    String typeCode = bean.typeCode;
                    if ("up".equals(typeCode) || "down".equals(typeCode) || "turnover".equals(typeCode) || "swing".equals(typeCode)){
                        rankList.add(bean);
                    }

                }
                fragment.initList(rankList);
            }

            @Override
            public void onFailure(Call<BaseListResponse<PlateListBean>> call, Throwable t) {
                fragment.onFailuer();
            }
        });
    }

}
